window.onload = function () {
    // 提交按钮触发弹出层
    $(".hand_out").click(function () {
        console.log("点击了提交按钮")
        $('.mask').css("display", "block");
    })

    // 确认提交
    $('.color_blue').click(function () {
        $('.mask').css("display", "none");
        send_Message();
    })

    // 取消提交
    $('.color_red').click(function () {
        $('.mask').css("display", "none");
    })
}

// 提交信息逻辑
// 发送按钮
function send_Message() {
    // 获取表单信息
    let author = localStorage.getItem("username")
    // console.log(author)
    let title = $('input[name="title"]').val();
    let content = $('textarea[name="novel"]').val();
    console.log("文本", author, title, content)
    $.ajax({
        type: "post",
        url: "./api/articles",
        data: { "ArticleTitle": title, "ArticleBody": content, "ArticleAuthor": author },
        dataType: "json",
        // 博客文章提交成功
        success: function (data) {
            console.log(data);
            $('input[name="title"]').val('')
            $('textarea[name="novel"]').val('')
            alert('提交成功')
            window.location.href = "./news";
        },
        // 提交失败
        error: function (data) {
            console.log(data);
            alert('提交失败')
        }
    });
}